home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-20 | 7.8 KB | 367 lines | [TEXT/MPS ] |
- /*
- File: SprocketSample.cp
-
- Contains: Boilerplate application-specific code.
-
- Written by: Dave Falkenburg
-
- Copyright: © 1993-94 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- <7> 12/6/94 DRF Gave this file a better name. Also stop defining kCreditsBox
- here.
- <6> 11/8/94 DRF (LDR) Modified to pass all non-standard menu selections through
- to window obj.
- <5> 11/8/94 DRF DoEditMenu is gone; call DoMenuSelection instead.
- <4> 9/28/94 DRF Changes for Dave Mark: More comments & rearranged code.
- <3> 9/27/94 DRF Changes for Dave Mark: AppLib.h is now Sprocket.h &
- clipboard conversion routines are fixed.
- <2> 9/9/94 DRF Reorganized headers and removed redundant #includes and
- conditionalized AOCE support.
- */
- #include "SprocketStarter.h"
- TLinkedList *gListPtr;
-
- #include "Sprocket.h"
- #include "Window.h"
- #include "StandardMenus.h"
- #include "SplashWindow.h"
- #include "FuturesDemo.h"
-
- #include <Desk.h>
- #include <Resources.h>
- #include <Errors.h>
-
- #include "ToolWindow.h"
- #include "PictureWindow.h"
- #include "TextWindow.h"
- #include "PreferencesDialogWindow.h"
- #include "MailableDocWindow.h"
-
- AppPreferences gPreferences;
-
- // Function Prototypes:
-
- void AboutBox(void);
- void OpenExistingDocument(void);
- OSErr CreateNewTextWindow(void);
- OSErr CreateNewPictureWindow(void);
-
-
- #define mDebug 256
- #define iNewMailableWindow 1
-
- #define kAboutBoxFor68K 256
- #define kAboutBoxForPowerPC 257
- #define iCreditsButton 2
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // SetupApplication
- //
- // Modify this function to provide any application-specific
- // initialization you may require.
- //
- // This is a good place to call EnterMovies, allocate
- // sound channels, setup network things, etc.
-
- OSErr
- SetupApplication(void)
- {
- #if 0
- gListPtr = new TLinkedList;
- #endif
-
- TToolWindow * someTools = new TToolWindow(1025);
-
- #if qAOCEAware
- gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
-
- InsertMenu(GetMenu(mDebug),0); // Add Debug Menu
- gMenuBar->RegisterCommand(cNewMailableWindow,mDebug,1);
- if (gHasAOCE)
- EnableCommand(cNewMailableWindow,true);
- #endif
- TTextWindow::SetUpStaticMenu();
- TPictureWindow::SetUpStaticMenu();
-
- InitCursor();
- InitFuturesDemo();
- return noErr;
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // CreateNewPictureWindow
- //
- // Create a new Picture window
-
- OSErr
- CreateNewPictureWindow(void)
- {
- TPictureWindow *aNewWindow = new TPictureWindow();
-
- if (aNewWindow)
- return noErr;
- else
- return memFullErr;
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // CreateNewTextWindow
- //
- // Create a new Text window
-
- OSErr
- CreateNewTextWindow(void)
- {
- TTextWindow *aNewWindow = new TTextWindow();
-
- if (aNewWindow)
- return noErr;
- else
- return memFullErr;
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // TearDownApplication
- //
- // Modify this function to tear down anything that you allocated
- // from within SetupApplication.
-
- void
- TearDownApplication(void)
- {
- CleanupFuturesDemo();
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // HandleMenuCommand
- //
- // Modify this function to handle any registered menu commands
- // that aren’t specific to a particular window.
-
- void
- HandleMenuCommand(MenuCommandID theCommand)
- {
- switch (theCommand)
- {
- case cAbout:
- AboutBox();
- break;
-
- case cNewTextWindow:
- CreateNewTextWindow();
- break;
-
- case cNewPictureWindow:
- CreateNewPictureWindow();
- break;
-
- case cCentered:
- SysBeep( 20 );
- break;
-
- case cUpperLeft:
- SysBeep( 20 );
- break;
-
- case cOpen:
- OpenExistingDocument();
- break;
-
- case cPreferences:
- TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
- break;
-
- #if qAOCEAware
- case cNewMailableWindow:
- TMailableDocWindow *aWackyThing = new TMailableDocWindow;
- break;
- #endif
-
- case cPing:
- SendSimpleAEvt(kSillyEventClass, kPing1Event);
- break;
-
- case cPing2:
- SendSimpleAEvt(kSillyEventClass, kPing2Event);
- break;
-
- default:
- break;
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // HandleMenuSelection
- //
- // Modify this function to handle any menu selections that aren’t
- // specific to a particular window. Normally, you shouldn’t need to
- // do anything, unless you hate using MenuCommands.
-
- void
- HandleMenuSelection(MenuID /* theMenu */, MenuItemID /* theItem */)
- {
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // ReadLocalClipboardFromScrap & WriteLocalClipboardToScrap
- //
- // These functions will be called whenever the user switches into
- // or out of your application.
- //
- // If you keep copy of the clipboard in your own data structures,
- // these functions will allow you to keep it in synch so that the
- // user can cut and paste information between your program and
- // other applications.
- //
- // We don’t actually use the clipboard in SprocketSample, so these
- // functions are empty for now.
-
- void
- ReadLocalClipboardFromScrap(void)
- {
- }
-
- void
- WriteLocalClipboardToScrap(void)
- {
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // CreateNewDocument, OpenDocument, PrintDocument, and
- // QuitApplication.
- //
- // These functions will be called whenever one of the required
- // AppleEvents is sent to your application— either when your
- // program is launched, or when the user opens a document from
- // the Finder.
-
- OSErr
- CreateNewDocument(void)
- {
- return CreateNewTextWindow();
- }
-
-
- OSErr
- OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
- {
- // Normally, you would open the file (or letter) and use the
- // information to create windows, etc.
-
- // For now, we just create a new document.
-
- return CreateNewDocument();
- }
-
-
- OSErr
- PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
- {
- // We don’t do printing yet, but you could.
- return errAEEventNotHandled;
- }
-
-
- Boolean QuitApplication(void)
- {
- // Just go ahead and say we’re done quitting…
-
- // Normally, you would offer to close any unsaved documents,
- // allowing the user to cancel along the way.
-
- #if 0
- unsigned long numLinks, counter;
- TDocWindow *myDocPtr;
-
- numLinks = gListPtr->CountLinks();
- for ( counter=1; counter<=numLinks; counter++ )
- {
- myDocPtr = (TDocWindow *)gListPtr->GetNthLinkObject( 1 );
- // If the user cancels the close, return false to
- // cancel the quit...
- if ( ! myDocPtr->Close() )
- return false;
- else
- delete myDocPtr;
- }
- #endif
-
- return true;
- }
-
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // AboutBox
- //
- // Put up our about box, including the version number. Depending
- // on what version we are running, pick the correct DLOG resource.
- //
-
- void
- AboutBox(void)
- {
- Handle versionHandle;
- StringPtr nullStr = (StringPtr) "\p";
- StringPtr shortVersionString = nullStr;
- short itemHit;
-
- versionHandle = GetResource('vers',1);
- if (versionHandle)
- shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
- ParamText(shortVersionString,nullStr,nullStr,nullStr);
- ReleaseResource(versionHandle);
-
- #if GENERATING68K
- itemHit = StandardAlert(kAboutBoxFor68K);
- #else
- itemHit = StandardAlert(kAboutBoxForPowerPC);
- #endif
-
- if (itemHit == iCreditsButton)
- StandardAlert(kCreditsBox);
- }
-
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // OpenExistingDocument
- //
- // Use StandardFile to ask the user for a file to open. We use
- // CustomGetFile so that we can properly handle update events
- // in other windows while the dialog is active.
-
- void
- OpenExistingDocument(void)
- {
- StandardFileReply reply;
- SFTypeList ourTypes;
-
- Point where = { -1, -1 };
-
- HiliteWindowsForModalDialog(false);
- CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
- (DlgHookYDUPP) nil,StandardDialogFilterYDUPP, nil,nil,nil);
- HiliteWindowsForModalDialog(true);
- }
-